<template>
	<view class="box fu">
		<view class="hezi" v-for="(item,index) in getlist" :key="index">
			<view class="box1">
				{{item.province}}{{item.city}}{{item.county}}{{item.address}}
			</view>
			<view class="box2">
				{{item.userName}} {{item.userPhone}}
			</view>
			<view class="box3">
				<span @click="bianji(index)">
					<uni-icons type="compose" size="16"></uni-icons>
					编辑
				</span>
				<span @click="del(index)">
					<uni-icons type="trash" size="16"></uni-icons>
					删除
				</span>
			</view>
		</view>
		<view class="kong" v-if="getlist.length == ''">
			<image class="img" src="../../static/tabbar/kong.png" mode=""></image>
			<view class="text">
				暂无数据
			</view>
		</view>
		<view class="" style="height: 120rpx;">
			
		</view>
		<view class="dibu">
			<button @click="chuangjian">创建新地址</button>
		</view>
	</view>
</template>

<script>
	import {
		getdelivery,
		removedelivery
	} from '@/common/http.api.js';
	export default {
		data() {
			return {
				getlist: []
			}
		},
		onShow() {
			this.getlie()
		},
		methods: {
			getlie() {
				let data = {}
				getdelivery(data).then(res => {
					this.getlist = res.data
				})
			},
			chuangjian() {
				let dataStr = encodeURIComponent(JSON.stringify(1));

				let url = '/pages/dizhi/adddizhi?data=' + dataStr;

				uni.navigateTo({
					url: url
				});
			},
			bianji(index) {
				let dataStr = encodeURIComponent(JSON.stringify(this.getlist[index]));

				let url = '/pages/dizhi/adddizhi?data=' + dataStr;

				uni.navigateTo({
					url: url
				});
			},
			del(index) {
				let arr = {
					id: this.getlist[index].id
				}
				let then = this
				uni.showModal({
					title: '有确认取消的弹窗',
					content: '确认要删除该项吗？',
					success: function(res) {
						if (res.confirm) {
							removedelivery(arr).then(res => {
								if (res.code == 200) {
									then.getlie()
									uni.showToast({
										title: '删除成功',
										duration: 2000,
										mask: false,
										icon: "none"
									})
								} else {
									uni.showToast({
										title: res.msg,
										duration: 2000,
										mask: false,
										icon: "none"
									})
								}
							})
						} else {
							console.log('点击了取消')
						}
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.dibu {
		width: 100%;
		position: fixed;
		bottom: 0%;
		height: 110rpx;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
		background-color: #fff;
		z-index: 99;
		button {
			margin-top: 20rpx;
			width: 710rpx;
			height: 80rpx;
			background: linear-gradient(84deg, #24180D 0%, #594629 100%);
			border-radius: 44rpx;
			font-family: PingFang SC;
			font-weight: bold;
			font-size: 30rpx;
			color: #FFFFFF;
			line-height: 80rpx;
		}
	}

	.hezi {
		width: 650rpx;
		height: 200rpx;
		background: #FFFFFF;
		border-radius: 20rpx;
		padding: 20rpx;
		margin-top: 20rpx;

		.box1 {
			font-family: PingFang SC;
			font-weight: bold;
			font-size: 28rpx;
			color: #0F0F0F;
			line-height: 36rpx;
		}

		.box2 {
			font-family: PingFang SC;
			font-weight: 500;
			font-size: 24rpx;
			color: #717171;
			margin: 25rpx 0rpx;
		}

		.box3 {
			display: flex;
			justify-content: flex-end;
			font-family: PingFang SC;
			font-weight: 500;
			font-size: 24rpx;
			color: #ABABAB;

			span {
				margin-left: 50rpx;
				display: flex;
				align-items: center;
			}
		}
	}
</style>